<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Users
 *
 * This model represents user authentication data. It operates the following tables:
 * - user account data,
 * - user profiles
 *
 * @package	Tank_auth
 * @author	Ilya Konyukhov (http://konyukhov.com/soft/)
 */
class Privileges_model extends CI_Model
{
	private $table_name			= 'privileges';			// user accounts

	function __construct(){
		parent::__construct();

	}
	
	function create_privileges($data){
		$data = array(
					'priv_name' => $this->input->post('priv_name'),
					'description' =>  $this->input->post('description'),
					'url' => $this->input->post('url')
					
				);
		$this->db->insert($this->table_name,$data);
	}
	
	function update_privileges($id_priv){
		$data = array(
					'priv_name' => $this->input->post('priv_name'),
					'description' =>  $this->input->post('description'),
					'url' => $this->input->post('url')
				);
		$this->db->where('id_priv', $id_priv);
        $this->db->update($this->table_name, $data);
	}
	
	function delete_privileges($id_priv){
		 $this->db->delete($this->table_name, array('id_priv'=>$id_priv)); 
	}
	
	function getAll($page='', $limit=''){
		if(!empty($limit))
		$this->db->limit($limit,$page);
		
		$query = $this->db->get('privileges');
		
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
	function select($id_priv){
        return $this->db->get_where('privileges', array('id_priv'=>$id_priv))->row();
    }
}